package com.jzo2o.orders.manager.client;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.jzo2o.api.foundations.ServeApi;
import com.jzo2o.api.foundations.dto.response.ServeAggregationResDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 客户端 服务保护组件类
 *
 * @Author mr.lin
 * @Date 2025/1/24 0:12
 */
@Component
@Slf4j
public class FoundationsClient {

    @Autowired
    private ServeApi serveApi;

    @SentinelResource(value = "serveDetailById", fallback = "ServeDetailFallback", blockHandler = "ServeDetailBlockHandler")
    public ServeAggregationResDTO serveDetailById(Long id) {
        return serveApi.findById(id);
    }


    //非熔断 限流走的方法(也就是程序异常走的方法)
    public ServeAggregationResDTO ServeDetailFallback(Long id, Throwable throwable) {
        log.error("非限流、熔断等导致的异常执行的降级方法，id:{},throwable:", id, throwable);
        return null;
    }

    //熔断,限流降级走的方法
    public ServeAggregationResDTO ServeDetailBlockHandler(Long id, BlockException blockException) {
        log.error("触发限流、熔断时执行的降级方法，id:{},blockException:", id, blockException);
        return null;
    }

}
